// 获取用户信息
exports.getUser = function(req,res){
	var select_user_name = req.query.USER_NAME;
	// console.log(req.query.USER_DATA);
	// console.log(select_user_name);
    req.getConnection(function(err,conn){
		if(err){
			console.log("Failed to connect");
			res.status(500).json(err);
		};
		
   		var querystring = 'SELECT * FROM user WHERE name=' + '\'' + select_user_name + '\'';
   		// console.log(querystring);
		var query = conn.query(querystring,function(err,rows){
			if(err){
				console.log(err);
				res.status(200).json({"user_data":""});//数据库无数据
			}else{
				console.log(rows);
				res.status(200).json({"user_data":rows});//数据库有数据
			}
		});
	})

};


// 注册用户信息
exports.addUser = function(req,res){
	var add_user_name = req.query.USER_NAME;
	var add_user_password = req.query.USER_PASSWORD;
	var add_user_authority = req.query.USER_AUTHORITY;
	// console.log(req.query);
	// console.log(add_user_password);
	// console.log(add_user_authority);
    req.getConnection(function(err,conn){
		if(err){
			console.log("Failed to connect");
			res.status(500).json(err);
		};
		//新的用户姓名、密码、权限写入表中
   		var querystring = 'INSERT INTO user(name,password,authority) VALUES (' + '\'' + add_user_name + '\',' + '\'' + add_user_password + '\',' + '\'' + add_user_authority + '\')';
   		// console.log(querystring);
		var query = conn.query(querystring,function(err,rows){
			if(err){
				console.log(err);
			}else{
				console.log(rows);
				res.status(200).json({"user_data":rows});
			}
		});
	})

};







